<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Easy
  </div>
  <div>
   <h1 class="question_title">
    1036. Rotting Oranges
   </h1>
   <p>
    In a given grid, each cell can have one of three&nbsp;values:
   </p>
   <ul>
    <li>
     the value
     <code>
      0
     </code>
     representing an empty cell;
    </li>
    <li>
     the value
     <code>
      1
     </code>
     representing a fresh orange;
    </li>
    <li>
     the value
     <code>
      2
     </code>
     representing a rotten orange.
    </li>
   </ul>
   <p>
    Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten.
   </p>
   <p>
    Return the minimum number of minutes that must elapse until no cell has a fresh orange.&nbsp; If this is impossible, return
    <code>
     -1
    </code>
    instead.
   </p>
   <p>
    &nbsp;
   </p>
   <div>
    <p>
     <strong>
      Example 1:
     </strong>
    </p>
    <p>
     <strong>
      <img alt="" src="https://assets.leetcode.com/uploads/2019/02/16/oranges.png" style="width: 712px; height: 150px;">
     </strong>
    </p>
    <pre>
<strong>Input: </strong><span id="example-input-1-1">[[2,1,1],[1,1,0],[0,1,1]]</span>
<strong>Output: </strong><span id="example-output-1">4</span>
</pre>
    <div>
     <p>
      <strong>
       Example 2:
      </strong>
     </p>
     <pre>
<strong>Input: </strong><span id="example-input-2-1">[[2,1,1],[0,1,1],[1,0,1]]</span>
<strong>Output: </strong><span id="example-output-2">-1</span>
<strong>Explanation: </strong> The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.
</pre>
     <div>
      <p>
       <strong>
        Example 3:
       </strong>
      </p>
      <pre>
<strong>Input: </strong><span id="example-input-3-1">[[0,2]]</span>
<strong>Output: </strong><span id="example-output-3">0</span>
<strong>Explanation: </strong> Since there are already no fresh oranges at minute 0, the answer is just 0.
</pre>
      <p>
       &nbsp;
      </p>
      <p>
       <strong>
        Note:
       </strong>
      </p>
      <ol>
       <li>
        <code>
         1 &lt;= grid.length &lt;= 10
        </code>
       </li>
       <li>
        <code>
         1 &lt;= grid[0].length &lt;= 10
        </code>
       </li>
       <li>
        <code>
         grid[i][j]
        </code>
        is only
        <code>
         0
        </code>
        ,
        <code>
         1
        </code>
        , or
        <code>
         2
        </code>
        .
       </li>
      </ol>
     </div>
    </div>
   </div>
  </div>
  <div>
   <h1 class="question_title">
    1036. 腐烂的橘子
   </h1>
   <p>
    在给定的网格中，每个单元格可以有以下三个值之一：
   </p>
   <ul>
    <li>
     值&nbsp;
     <code>
      0
     </code>
     &nbsp;代表空单元格；
    </li>
    <li>
     值&nbsp;
     <code>
      1
     </code>
     &nbsp;代表新鲜橘子；
    </li>
    <li>
     值&nbsp;
     <code>
      2
     </code>
     &nbsp;代表腐烂的橘子。
    </li>
   </ul>
   <p>
    每分钟，任何与腐烂的橘子（在 4 个正方向上）相邻的新鲜橘子都会腐烂。
   </p>
   <p>
    返回直到单元格中没有新鲜橘子为止所必须经过的最小分钟数。如果不可能，返回&nbsp;
    <code>
     -1
    </code>
    。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1：
    </strong>
   </p>
   <p>
    <strong>
     <img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/02/16/oranges.png" style="height: 150px; width: 712px;">
    </strong>
   </p>
   <pre><strong>输入：</strong>[[2,1,1],[1,1,0],[0,1,1]]
<strong>输出：</strong>4
</pre>
   <p>
    <strong>
     示例 2：
    </strong>
   </p>
   <pre><strong>输入：</strong>[[2,1,1],[0,1,1],[1,0,1]]
<strong>输出：</strong>-1
<strong>解释：</strong>左下角的橘子（第 2 行， 第 0 列）永远不会腐烂，因为腐烂只会发生在 4 个正向上。
</pre>
   <p>
    <strong>
     示例 3：
    </strong>
   </p>
   <pre><strong>输入：</strong>[[0,2]]
<strong>输出：</strong>0
<strong>解释：</strong>因为 0 分钟时已经没有新鲜橘子了，所以答案就是 0 。
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= grid.length &lt;= 10
     </code>
    </li>
    <li>
     <code>
      1 &lt;= grid[0].length &lt;= 10
     </code>
    </li>
    <li>
     <code>
      grid[i][j]
     </code>
     仅为&nbsp;
     <code>
      0
     </code>
     、
     <code>
      1
     </code>
     &nbsp;或&nbsp;
     <code>
      2
     </code>
    </li>
   </ol>
  </div>
 </body>
</html>